package com.stone.cat.adapter.impl;

import com.google.common.collect.Lists;
import com.stone.cat.adapter.MyServiceExecutor2;
import com.stone.cat.common.util.BeanUtil;
import com.stone.cat.facade.pojo.response.CatBaseResponseDTO;
import com.stone.cat.facade.pojo.vo.TopVO;
import com.stone.cat.facade.service.HomeManagerService;
import com.stone.cat.facade.service.MyBaseService;
import com.stone.cat.persist.mybatis.mapper.TopMapper;
import com.stone.cat.persist.mybatis.model.Top;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by 喵 on 2018/2/5.
 */
@Service
public class HomeManagerServiceImpl extends MyBaseService implements HomeManagerService {

    @Autowired
    private TopMapper topMapper;

    @Override
    @Transactional
    public CatBaseResponseDTO<TopVO> listTop() {
        return this.execute(CatBaseResponseDTO.class, new MyServiceExecutor2<CatBaseResponseDTO>() {
            @Override
            protected CatBaseResponseDTO myProcess() throws Exception {
                CatBaseResponseDTO response = new CatBaseResponseDTO();
                List<Top> tops = topMapper.selectByExample(null);
                List<TopVO> vos = Lists.newArrayListWithCapacity(5);
                BeanUtil.copyPropertiesList(vos,tops,TopVO.class);
                response.setData(vos);
                return response;
            }
        });
    }
}
